In [2]:
N = 10 ** 7
div = [1]*(N+1)
for p in range(2,N+1):
if div[p] == 1:
div[p] = p
for k in range(p*p, N+1, p):
div[k] = p
count = 0
for n in range(2, N+1):
p = div[n]
m = n//p
div[n] = div[m]
while m % p == 0:
m //= p
div[n] += div[m]
count += (div[n] == div[n-1])
print(count)
In [ ]: